<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">

      <el-form-item label="计划月份" >
        <el-date-picker
          v-model="queryParams.planMonth"
          type="month"
          format="yyyy-MM"
          value-format="yyyy-MM"
          size="small"
          @change="search"
          placeholder="选择月">
        </el-date-picker>
        <el-form-item label="申请名称" >
          <el-input
            v-model="queryParams.pickName"
            placeholder="请输入申请名称"
            clearable
            size="small"
          />
        </el-form-item>

      </el-form-item>
      <el-form-item>
        <el-button  type="primary" icon="el-icon-search" size="mini" @click="search">搜索</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="roleList" stripe border>
      <el-table-column align="center" type="index" label="序号"  width="55"  />
      <el-table-column align="center" label="审核状态"   property="storageSteps"  width="100" >
        <template slot-scope="scope" style="text-align: center">
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.storageSteps==1">未提交</div>
          <div style="background:#78BF34  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.storageSteps==2">经管科</div>
          <div style="background:#9E71DC  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.storageSteps==3">财务</div>
          <div style="background:#DEA11E  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.storageSteps==4">入库</div>
          <div style="background:#EE113D  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.storageSteps==5">驳回</div>
          <div style="background:#DEA11E  ;color: white;width: 54px;height: 22px;display: inline-block" v-show="scope.row.storageSteps==6">完成</div>

        </template>
      </el-table-column>
      <el-table-column align="center" label="申请名称"  property="pickName" ></el-table-column>
      <el-table-column align="center" label="计划月份" property="planMonth" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="用途"  property="useing" :show-overflow-tooltip="true"  ></el-table-column>
      <el-table-column align="center" label="仓库名称"  property="waName" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column align="center" label="创建时间"  property="crtTime" :show-overflow-tooltip="true" ></el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="400px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="danger"
            style="margin-left: 20px"
            icon="el-icon-close"
            @click="tijiao(scope.$index, scope.row)">驳回</el-button>
          <el-button
            size="mini"
            type="primary"
            icon="el-icon-check"
            @click="tongguo(scope.$index, scope.row)">通过</el-button>
          <el-button
            size="mini"
            type="success"
            icon="el-icon-s-unfold"
            @click="xingqing(scope.row)">详情</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="search"
    />


  </div>
</template>

<script>
  import request from '@/utils/request'

  export default {
    name: "Role",
    components:{

    },
    data() {
      return {
        //记录分页数据
        localPage:undefined,
        localSize:undefined,
        XQme:'puSP',
        shifouList:[
          {value:'1',label:'是'},
          {value:'2',label:'否'}
        ],
        //仓库
        statusCK:[
          {value:'1',label:'1111'}
        ],
        kuncunData:{},
        kucunShow:false,
        // 遮罩层
        loading: false,
        // 总条数
        total: 0,
        // 角色表格数据
        roleList: [],
        // 日期范围
        dateRange: [],
        //科室
        keshiList:[
          { value: '1',label: '科室1'},
          { value: '2',label: '科室2'},
          { value: '3',label: '科室3'},
        ],
        // 状态数据字典
        statusOptions: [
          { value: '1',label: '进行中'},
          { value: '2',label: '已结束'},
          { value: '3',label: '未提交'},
        ],
        // 数据范围选项
        dataScopeOptions: [
          {
            value: "1",
            label: "全部数据权限"
          },
          {
            value: "2",
            label: "自定数据权限"
          },
          {
            value: "3",
            label: "本部门数据权限"
          },
          {
            value: "4",
            label: "本部门及以下数据权限"
          },
          {
            value: "5",
            label: "仅本人数据权限"
          }
        ],
        // 菜单列表
        menuOptions: [],
        // 部门列表
        deptOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          pickName:'',
          planMonth:'',
        },
        // 表单参数
        form: {},
        defaultProps: {
          children: "children",
          label: "label"
        },
      };
    },
    created() {
      var myDate = new Date();
      var pp =myDate.getMonth()+1;       //获取当前月份(0-11,0代表1月)
      if(pp<9){
        pp = "0"+pp
      }
      this.queryParams.planMonth = myDate.getFullYear()+'-'+pp;
      this.jlPage()
      this.search()

    },
    methods: {
      //转换时间戳
      zhuanhuanDate:function(row){
        var oldTime = new Date(row)
        var year=oldTime.getFullYear();
        var month=oldTime.getMonth()+1;
        var date=oldTime.getDate();
        var pp = year+'-'+month+'-'+date
        return  pp
      },

      //新增
      cgjhadd:function () {
        var pp={
          leixng:'post',
        }
        this.$router.push({path:'/warehouseManagement/theOtherAdd',query:pp});
      },
      //库存管理返回
      kucunBack:function(row){
        this.kucunShow = false
        console.log('返回数据',row)
      },
      //记录页码数据
      jlPage () {
        this.localSize = this.$route.query.size
      this.localPage = this.$route.query.page
      console.log(this.$route.query.page)
      if(this.localPage!==undefined) {
          this.queryParams.pageNum = this.localPage
          console.log(111)
      }
      if(this.localSize!==undefined) {
        this.queryParams.pageSize = this.localSize
      }
      },
      //查询
      search:function(){
        this.loading = true
        this.localPage = this.queryParams.pageNum
        this.localSize = this.queryParams.pageSize
        request({
          url: '/material/apply/listWarehouseManagement',
          method: 'get',
          params:this.queryParams
        }).then(response => {
          this.loading = false
          this.roleList = response.rows
          for (var i=0;i<this.roleList.length;i++){
            if(this.roleList[i].crtTime){
              this.roleList[i].crtTime = this.zhuanhuanDate(this.roleList[i].crtTime)
            }

          }
          this.total = response.total
        });
      },
      //详情
      xingqing:function (row) {
        var pp={
          row:row
        }
        this.$router.push({path:'/warehouseManagement/theOtherXQ',query:{pp,page:this.localPage,size:this.localSize,xq:this.XQme}});
      },
      //通过
      tongguo:function(index,row){
        this.$confirm('确认要通过当前数据吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.tijiaoBtn(row,6)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消通过'
          });
        });
      },
      //驳回
      tijiao:function(index,row){
        this.$confirm('确认要驳回当前数据吗?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.tijiaoBtn(row,5)
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消驳回'
          });
        });
      },
      tijiaoBtn:function(row,num){
        request({
          url: '/material/apply/reviewTheStatus',
          method: 'post',
          data: {
            id: row.id,
            storageSteps:num
          }
        }).then(response => {
          this.$message({
            type: 'success',
            message:response.msg
          });
          this.search()
        });
      },

    }
  };
</script>
